import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  UseGuards,
  Query,
} from '@nestjs/common';
import { CandidateService } from './candidate.service';
import {
  CandidateDto,
  CandidateUpdDto,
  QueryCandidateDto,
} from './dto/candidate.dto';
import { AuthGuard } from '../../@nt/guards/auth.guard';
import { AdminGuard } from '../../@nt/guards/admin.guard';
import { RestController } from '../../@nt';

// 候选人控制器
@Controller('candidate')
@UseGuards(AuthGuard)
export class CandidateController extends RestController {
  constructor(protected readonly service: CandidateService) {
    super(service);
  }

  // 创建候选人
  @Post()
  @UseGuards(AdminGuard)
  async create(@Body() body: CandidateDto) {
    return await this.service.create(body);
  }

  // 查询候选人列表
  @Get()
  async findAll(@Query() query: QueryCandidateDto): Promise<any> {
    return await this.service.findAll(query);
  }

  // 查询候选人详情
  @Get(':id')
  async findOne(@Param('id') id: string): Promise<any> {
    return await this.service.findOne(+id);
  }

  // 更新候选人信息
  @Patch(':id')
  @UseGuards(AdminGuard)
  async update(
    @Param('id') id: string,
    @Body() body: CandidateUpdDto,
  ): Promise<any> {
    return await this.service.update(+id, body);
  }
}
